/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroVeiculo.java
 *
 * Created on 05/04/2011, 01:02:53
 */
package Tela;

import Classe.BD;
import Classe.Marca;
import Classe.Modelo;
import Classe.Validacao;
import Classe.Veiculo;
import java.awt.Component;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author gladson
 */
public class CadastroVeiculo extends Validacao {

    Veiculo veiculo;
    int testPJouPJ;
    private Component frameI;
    int idCli;
    int idCliPJ;

    /** Creates new form CadastroVeiculo */
    public CadastroVeiculo() {
        initComponents();
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        iniciar();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        PanelCadastroVeiculo = new javax.swing.JPanel();
        pnlCadastroVeiculo = new javax.swing.JPanel();
        lblClienteVeiculo = new javax.swing.JLabel();
        sTxtClienteVeiculo = new javax.swing.JTextField();
        lblPlcaVeiculo = new javax.swing.JLabel();
        lblAnoVeiculo = new javax.swing.JLabel();
        lblMarcaVeiculo = new javax.swing.JLabel();
        cbMarcaVeiculo = new javax.swing.JComboBox();
        lblModeloVeiculo = new javax.swing.JLabel();
        cbModeloVeiculo = new javax.swing.JComboBox();
        btAddMarcaVeiculo = new javax.swing.JButton();
        btAddModeloVeiculo = new javax.swing.JButton();
        lblCorVeiculo = new javax.swing.JLabel();
        sTxtCorVeiculo = new javax.swing.JTextField();
        sTxPlacaVeiculo = new javax.swing.JFormattedTextField();
        sTxtAnoVeiculo = new javax.swing.JFormattedTextField();
        btSalvarVeiculo = new javax.swing.JButton();
        btLimparVeiculo = new javax.swing.JButton();
        btSairVeiculo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        PanelCadastroVeiculo.setBackground(new java.awt.Color(255, 255, 255));
        PanelCadastroVeiculo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Cadastro de Veículo ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("PMingLiU", 0, 36))); // NOI18N

        pnlCadastroVeiculo.setBackground(new java.awt.Color(255, 255, 255));
        pnlCadastroVeiculo.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lblClienteVeiculo.setFont(new java.awt.Font("Arial", 1, 11));
        lblClienteVeiculo.setText("Cliente");

        sTxtClienteVeiculo.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        lblPlcaVeiculo.setFont(new java.awt.Font("Arial", 1, 11));
        lblPlcaVeiculo.setText("Placa");

        lblAnoVeiculo.setFont(new java.awt.Font("Arial", 1, 11));
        lblAnoVeiculo.setText("Ano");

        lblMarcaVeiculo.setFont(new java.awt.Font("Arial", 1, 11));
        lblMarcaVeiculo.setText("Marca");

        cbMarcaVeiculo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { }));
        cbMarcaVeiculo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cbMarcaVeiculo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbMarcaVeiculoItemStateChanged(evt);
            }
        });

        lblModeloVeiculo.setFont(new java.awt.Font("Arial", 1, 11));
        lblModeloVeiculo.setText("Modelo");

        cbModeloVeiculo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { }));
        cbModeloVeiculo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        btAddMarcaVeiculo.setText("+");
        btAddMarcaVeiculo.setToolTipText("Cadastro de Marcas");
        btAddMarcaVeiculo.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btAddMarcaVeiculo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddMarcaVeiculoActionPerformed(evt);
            }
        });

        btAddModeloVeiculo.setText("+");
        btAddModeloVeiculo.setToolTipText("Cadastro de Modelos");
        btAddModeloVeiculo.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btAddModeloVeiculo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddModeloVeiculoActionPerformed(evt);
            }
        });

        lblCorVeiculo.setFont(new java.awt.Font("Arial", 1, 11));
        lblCorVeiculo.setText("Cor");

        sTxtCorVeiculo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        sTxPlacaVeiculo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            sTxPlacaVeiculo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("UUU-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        sTxtAnoVeiculo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            sTxtAnoVeiculo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout pnlCadastroVeiculoLayout = new javax.swing.GroupLayout(pnlCadastroVeiculo);
        pnlCadastroVeiculo.setLayout(pnlCadastroVeiculoLayout);
        pnlCadastroVeiculoLayout.setHorizontalGroup(
            pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCadastroVeiculoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sTxtClienteVeiculo, javax.swing.GroupLayout.DEFAULT_SIZE, 716, Short.MAX_VALUE)
                    .addComponent(lblClienteVeiculo)
                    .addGroup(pnlCadastroVeiculoLayout.createSequentialGroup()
                        .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPlcaVeiculo)
                            .addComponent(sTxPlacaVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlCadastroVeiculoLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(sTxtAnoVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlCadastroVeiculoLayout.createSequentialGroup()
                                .addGap(13, 13, 13)
                                .addComponent(lblAnoVeiculo)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblCorVeiculo)
                            .addComponent(sTxtCorVeiculo, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)))
                    .addComponent(lblMarcaVeiculo)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlCadastroVeiculoLayout.createSequentialGroup()
                        .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblModeloVeiculo, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbMarcaVeiculo, javax.swing.GroupLayout.Alignment.LEADING, 0, 681, Short.MAX_VALUE)
                            .addComponent(cbModeloVeiculo, javax.swing.GroupLayout.Alignment.LEADING, 0, 681, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btAddModeloVeiculo)
                            .addComponent(btAddMarcaVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        pnlCadastroVeiculoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btAddMarcaVeiculo, btAddModeloVeiculo});

        pnlCadastroVeiculoLayout.setVerticalGroup(
            pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCadastroVeiculoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblClienteVeiculo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sTxtClienteVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlCadastroVeiculoLayout.createSequentialGroup()
                        .addComponent(lblPlcaVeiculo)
                        .addGap(26, 26, 26))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlCadastroVeiculoLayout.createSequentialGroup()
                        .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblAnoVeiculo)
                            .addComponent(lblCorVeiculo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(sTxPlacaVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(sTxtAnoVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlCadastroVeiculoLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(sTxtCorVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblMarcaVeiculo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbMarcaVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btAddMarcaVeiculo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblModeloVeiculo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btAddModeloVeiculo)
                    .addComponent(cbModeloVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlCadastroVeiculoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btAddMarcaVeiculo, cbMarcaVeiculo});

        pnlCadastroVeiculoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btAddModeloVeiculo, cbModeloVeiculo});

        btSalvarVeiculo.setFont(new java.awt.Font("Arial", 0, 12));
        btSalvarVeiculo.setText("Salvar");
        btSalvarVeiculo.setToolTipText("Salvar");
        btSalvarVeiculo.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btSalvarVeiculo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarVeiculoActionPerformed(evt);
            }
        });

        btLimparVeiculo.setFont(new java.awt.Font("Arial", 0, 12));
        btLimparVeiculo.setText("Limpar");
        btLimparVeiculo.setToolTipText("Limpar");
        btLimparVeiculo.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btLimparVeiculo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLimparVeiculoActionPerformed(evt);
            }
        });

        btSairVeiculo.setFont(new java.awt.Font("Arial", 0, 12));
        btSairVeiculo.setText("Sair");
        btSairVeiculo.setToolTipText("Sair");
        btSairVeiculo.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btSairVeiculo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSairVeiculoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout PanelCadastroVeiculoLayout = new javax.swing.GroupLayout(PanelCadastroVeiculo);
        PanelCadastroVeiculo.setLayout(PanelCadastroVeiculoLayout);
        PanelCadastroVeiculoLayout.setHorizontalGroup(
            PanelCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelCadastroVeiculoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlCadastroVeiculo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(PanelCadastroVeiculoLayout.createSequentialGroup()
                        .addComponent(btSalvarVeiculo)
                        .addGap(18, 18, 18)
                        .addComponent(btLimparVeiculo)
                        .addGap(18, 18, 18)
                        .addComponent(btSairVeiculo)))
                .addContainerGap())
        );

        PanelCadastroVeiculoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btLimparVeiculo, btSairVeiculo, btSalvarVeiculo});

        PanelCadastroVeiculoLayout.setVerticalGroup(
            PanelCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelCadastroVeiculoLayout.createSequentialGroup()
                .addComponent(pnlCadastroVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(PanelCadastroVeiculoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btSalvarVeiculo)
                    .addComponent(btSairVeiculo)
                    .addComponent(btLimparVeiculo))
                .addContainerGap(270, Short.MAX_VALUE))
        );

        PanelCadastroVeiculoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btLimparVeiculo, btSairVeiculo, btSalvarVeiculo});

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PanelCadastroVeiculo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PanelCadastroVeiculo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-808)/2, (screenSize.height-627)/2, 808, 627);
    }// </editor-fold>//GEN-END:initComponents

    private void btSairVeiculoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairVeiculoActionPerformed
        this.dispose();
        // TODO add your handling code here:
}//GEN-LAST:event_btSairVeiculoActionPerformed

    private void btAddMarcaVeiculoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddMarcaVeiculoActionPerformed
        // TODO add your handling code here:
        CadastroMarca marca = new CadastroMarca();
        marca.setVisible(true);
        marca.pegar(this);
        
    }//GEN-LAST:event_btAddMarcaVeiculoActionPerformed

    private void btAddModeloVeiculoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddModeloVeiculoActionPerformed
        // TODO add your handling code here:
        CadastroModelo modelo = new CadastroModelo();
        modelo.setVisible(true);
        modelo.pegar(this);
        this.setVisible(true);
    }//GEN-LAST:event_btAddModeloVeiculoActionPerformed

    private void cbMarcaVeiculoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbMarcaVeiculoItemStateChanged

        try {

            cbModeloVeiculo.removeAllItems(); // limpa a caixa atual.

            if (cbMarcaVeiculo.getSelectedItem() != null) {

                Marca itemMarca = (Marca) cbMarcaVeiculo.getSelectedItem();

                String sql = "Select * from modelo where id_marca = '" + itemMarca.getIdMarca() + "' order by modelo";

                BD bd = new BD();
                ResultSet r = bd.consultar(sql);

                Modelo modelo = new Modelo();

                cbModeloVeiculo.addItem(null);

                while (r.next()) {

                    Modelo modeloVei = new Modelo();

                    modeloVei.setIdModelo(r.getInt("id_modelo"));
                    modeloVei.setModelo(r.getString("modelo"));

                    cbModeloVeiculo.addItem(modeloVei);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }//GEN-LAST:event_cbMarcaVeiculoItemStateChanged

    private void btSalvarVeiculoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarVeiculoActionPerformed
        if (validar()) {//confirmando se a validação dos campos pelo metodo validação

            try {
                veiculo = new Veiculo();

                veiculo.setPlacaVeiculo(sTxPlacaVeiculo.getText().trim().toUpperCase());
                veiculo.setAnoVeiculo(sTxtAnoVeiculo.getText().trim().toUpperCase());
                veiculo.setCorVeiiculo(sTxtCorVeiculo.getText().trim().toUpperCase());

                if (testPJouPJ == 1) {
                    Modelo itemMod = (Modelo) cbModeloVeiculo.getSelectedItem();

                    String sql = "insert into veiculo (id_veiculo,placa_veiculo,ano_veiculo,cor_veiculo,id_cliente,id_modelo) values (sq_veiculo.nextval,?,?,?,?,?)";
                    Object[] parametros = {veiculo.getPlacaVeiculo(), veiculo.getAnoVeiculo(), veiculo.getCorVeiiculo(), idCli, itemMod.getIdModelo()};
                    Object[] tipos = {String.class, String.class, String.class, Integer.class, Integer.class};

                    BD banco = new BD();
                    banco.executar(sql, parametros, tipos);
                } else if (testPJouPJ == 2) {
                    Modelo itemMod = (Modelo) cbModeloVeiculo.getSelectedItem();
                    String sql = "insert into veiculo (id_veiculo,placa_veiculo,ano_veiculo,cor_veiculo,id_modelo,id_cliente_pj) values (sq_veiculo.nextval,?,?,?,?,?)";
                    Object[] parametros = {veiculo.getPlacaVeiculo(), veiculo.getAnoVeiculo(), veiculo.getCorVeiiculo(), itemMod.getIdModelo(), idCliPJ};
                    Object[] tipos = {String.class, String.class, String.class, Integer.class, Integer.class};

                    BD banco = new BD();
                    banco.executar(sql, parametros, tipos);

                }

                sTxPlacaVeiculo.setText("");
                sTxtAnoVeiculo.setText("");
                sTxtCorVeiculo.setText("");
                iniciar();
                JOptionPane.showMessageDialog(frameI, "Cadastro salvo com Sucesso");
            } catch (Exception ex) {
                ex.printStackTrace();

            }
        }
    }//GEN-LAST:event_btSalvarVeiculoActionPerformed

    private void btLimparVeiculoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLimparVeiculoActionPerformed
        sTxPlacaVeiculo.setText("");
        sTxtAnoVeiculo.setText("");
        sTxtCorVeiculo.setText("");
        iniciar();
    }//GEN-LAST:event_btLimparVeiculoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CadastroVeiculo().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PanelCadastroVeiculo;
    private javax.swing.JButton btAddMarcaVeiculo;
    private javax.swing.JButton btAddModeloVeiculo;
    private javax.swing.JButton btLimparVeiculo;
    private javax.swing.JButton btSairVeiculo;
    private javax.swing.JButton btSalvarVeiculo;
    private javax.swing.JComboBox cbMarcaVeiculo;
    private javax.swing.JComboBox cbModeloVeiculo;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblAnoVeiculo;
    private javax.swing.JLabel lblClienteVeiculo;
    private javax.swing.JLabel lblCorVeiculo;
    private javax.swing.JLabel lblMarcaVeiculo;
    private javax.swing.JLabel lblModeloVeiculo;
    private javax.swing.JLabel lblPlcaVeiculo;
    private javax.swing.JPanel pnlCadastroVeiculo;
    private javax.swing.JFormattedTextField sTxPlacaVeiculo;
    private javax.swing.JFormattedTextField sTxtAnoVeiculo;
    private javax.swing.JTextField sTxtClienteVeiculo;
    private javax.swing.JTextField sTxtCorVeiculo;
    // End of variables declaration//GEN-END:variables

    public void inicializarPF(String nome, int idcliente) {
        sTxtClienteVeiculo.setText(nome); //PREENCHENDO O CAMPO CLIENTE NA TELA
        sTxtClienteVeiculo.setEnabled(false);// DESABILITANDO A EDIÇÃO DO CAMPO
        idCli = idcliente; //SALVADO O ID DO CLIENTE QUE VEIO DA TELA CLIENTE.
        testPJouPJ = 1;
    }

    public void inicializarPJ(String nome, int idclientePJ) {
        sTxtClienteVeiculo.setText(nome); //PREENCHENDO O CAMPO CLIENTE NA TELA
        sTxtClienteVeiculo.setEnabled(false);// DESABILITANDO A EDIÇÃO DO CAMPO
        idCliPJ = idclientePJ; //SALVADO O ID DO CLIENTE QUE VEIO DA TELA CLIENTE.
        testPJouPJ = 2;

    }

    public void iniciar() {
        try {
            String sql = "Select * from marca order by marca";
            BD bd = new BD();
            ResultSet r1 = bd.consultar(sql);
            cbMarcaVeiculo.removeAllItems();
            Marca marca1 = new Marca();
            cbMarcaVeiculo.addItem(null);

            while (r1.next()) {
                Marca marca = new Marca();
                int id_marca = r1.getInt("id_marca");
                String nome_marca = r1.getString("marca");

                marca.setIdMarca(id_marca);
                marca.setNomeMarca(nome_marca);

                cbMarcaVeiculo.addItem(marca);
            }



        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }
    }

    public boolean validar() {
        boolean Resultado = true;

        if (sTxPlacaVeiculo.getText().trim().equals("-")) {
            JOptionPane.showMessageDialog(frameI, "Obrigatório preencher o campo placa");
            Resultado = false;
        } else if (sTxtAnoVeiculo.getText().trim().equals("/")) {
            JOptionPane.showMessageDialog(frameI, "Obrigatório preencher o campo ano");
            Resultado = false;
        } else if (validarNome(sTxtCorVeiculo.getText().trim()) == false) {
            Resultado = false;
        } else if (cbMarcaVeiculo.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(frameI, "Obrigatório selecionar a marca");
            Resultado = false;
        } else if (cbModeloVeiculo.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(frameI, "Obrigatório selecionar a modelo");
            Resultado = false;
        }

        return Resultado;
    }
}
